package com.think.archive.controller.api;

import com.think.archive.common.ResultBean;
import com.think.archive.dto.SysRoleDto;
import com.think.archive.model.SysDept;
import com.think.archive.model.SysRole;
import com.think.archive.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api")
public class RoleController {

    @Autowired
    SysRoleService roleService;

    @GetMapping("roles")
    public ResultBean getRoles(@RequestParam(value = "roleCode", required = false) String roleCode){
        List<SysRoleDto> roles=roleService.findNextLevelRoleDto(roleCode);
        return ResultBean.createResultBySuccess(roles);
    }

    @PostMapping("saveRole")
    public ResultBean saveRole(SysRole role){
        return ResultBean.createResultBySuccess(roleService.insertOrUpdateRole(role));
    }

    @PostMapping("deleteRole")
    public ResultBean deleteRole(int id){
        return ResultBean.createResultBySuccess(roleService.deleteRole(id));
    }

    @RequestMapping("role/state/change")
    public ResultBean changeStatusRole(int id ,String status){
        int res=roleService.changeStatusRole(id,status);
        return ResultBean.createResultBySuccess(res);
    }

    @RequestMapping("/api/role/func")
    public ResultBean roleFunc(String roleId){
        return ResultBean.createResultBySuccess(null);
    }

}
